package com.platform.wechat.controller;

import com.platform.wechat.common.JsonBean;
import com.platform.wechat.entity.Platform;
import com.platform.wechat.service.PlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @author 嗷嗷嗷
 * @title: PlatformController
 * @projectName wechat114
 * @description: TODO
 * @date 2021/7/2820:03
 */
@RestController
@RequestMapping("platform")
public class PlatformController {

    @Autowired
    private PlatformService platformService;

    /**
     * 登陆
     * @param platformPhone
     * @param code
     * @param session
     * @return
     */
    @RequestMapping("select")
    public JsonBean select(String platformPhone,String code, HttpSession session){
        JsonBean jsonBean = new JsonBean(-1,"ok",null);
        if (Integer.parseInt(code)==111111){
            session.removeAttribute("platformPhone");
            session.setAttribute("platformPhone",platformPhone);
            jsonBean = platformService.selest(platformPhone);
        }else{
            jsonBean.setMsg("验证码错误");
        }
        return jsonBean;
    }

    /**
     * 实名认证
     * @param platform
     * @param session
     * @return
     */
    @RequestMapping("autonym")
    public JsonBean autonym(Platform platform, HttpSession session){
            Object platformPhone = session.getAttribute("platformPhone");
            platform.setPlatformPhone(String.valueOf(platformPhone));
            JsonBean insert = platformService.insert(platform);
        return insert;
    }

    /**
     * 修改手机号
     * @param platformPhone
     * @param session
     * @return
     */
    @RequestMapping("update")
    public JsonBean update(String platformPhone, String code,HttpSession session){
        Platform platform = new Platform();
        platform.setPlatformPhone(platformPhone);
        JsonBean jsonBean = new JsonBean(-1,"ok",null);
        if (Integer.parseInt(code)==111111){
            Object Phone = session.getAttribute("platformPhone");
            String phone = String.valueOf(Phone);
            session.removeAttribute("platformPhone");
            session.setAttribute("platformPhone",platformPhone);
            jsonBean = platformService.update(platform,phone);
        }else{
            jsonBean.setMsg("验证码错误");
        }
        return jsonBean;
    }

    /**
     * 拿session
     * @param session
     * @return
     */
    @RequestMapping("acquisitionSession")
    public String acquisitionSession(HttpSession session){
        Object Phone = session.getAttribute("platformPhone");
        String phone = String.valueOf(Phone);
        return phone;
    }

    /**
     * 查询实名认证信息
     * @param session
     * @return
     */
    @RequestMapping("state")
    public JsonBean selects(HttpSession session){
        Object Phone = session.getAttribute("platformPhone");
        String phone = String.valueOf(Phone);
        JsonBean selects = platformService.selects(phone);

        System.err.println(selects);
        return selects;
    }

}
